package com.cloudsigns.factorymanager2.project.presenter;

import com.cloudsigns.factorymanager2.project.iview.IAddEngineeringBatchInstallationOrderView;
import com.cloudsigns.factorymanager2.project.iview.IAddEngineeringInstallationOrderView;
import com.cloudsigns.factorymanager2.project.model.AddEngineeringBatchInstallationOrderModel;
import com.cloudsigns.factorymanager2.project.model.AddEngineeringInstallationOrderModel;
import com.cloudsigns.factorymanager2.project.model.IAddEngineeringBatchInstallationOrderModel;
import com.cloudsigns.factorymanager2.project.model.IAddEngineeringInstallationOrderModel;

/**
 * Created by tony on 2018/3/17.
 */

public class AddEngineeringBatchInstallationOrderPresenter {
    private IAddEngineeringBatchInstallationOrderView view;
    private IAddEngineeringBatchInstallationOrderModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public AddEngineeringBatchInstallationOrderPresenter(IAddEngineeringBatchInstallationOrderView view) {
        this.view = view;
        this.model = new AddEngineeringBatchInstallationOrderModel();
    }

    public void addEngineeringBatchInatallationOrder() {

        model.addEngineeringBatchInatallationOrder(view.getCompleteDate(), view.getEngineeringBeanList(), view.getProjectName(), new AddEngineeringBatchInstallationOrderModel.OnAddEngineeringBatchInstallationOrderListener() {

            @Override
            public void success(final String projectId) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.addEngineeringBatchInstallatonOrderSuccess(projectId);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }
        });

    }

}
